package com.dldata.devtools30.repository.common;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

@Slf4j
public class JdbcTemplateProxy implements InvocationHandler {

    JdbcTemplate jdbcTemplate;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        log.trace(JSON.toJSONString(args));
        Object result = method.invoke(jdbcTemplate, args);

        return result;
    }

    public static JdbcTemplateProxy newJdbcTemplateProxy(JdbcTemplate jdbcTemplate){
        JdbcTemplateProxy jdbcTemplateProxy = new JdbcTemplateProxy();
        jdbcTemplateProxy.jdbcTemplate=jdbcTemplate;
        return jdbcTemplateProxy;
    }
}
